/*
   Copyright (c) 2019 Shanghai Xuanzi Technology Co. Ltd https://xuanzi.ltd
   XZMindMap is licensed under the Mulan PSL v1.
   You can use this software according to the terms and conditions of the Mulan PSL v1.
   You may obtain a copy of Mulan PSL v1 at:
      http://license.coscl.org.cn/MulanPSL
   THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
   IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
   PURPOSE.
   See the Mulan PSL v1 for more details.

*/

package xuanzi.openmind.scenes.base;

import xuanzi.commons.graphics.PointF;
import xuanzi.openmind.layout.Box;
import xuanzi.openmind.layout.HBox;
import xuanzi.openmind.layout.VBox;
import xuanzi.openmind.nodes.Node;

public class ThinkTreeNorthScene extends BoxScene{
 
	Box left = new VBox();
	
	Box right = new VBox();
	
	int align;
	
	public ThinkTreeNorthScene() {
		  
	}
	
	@Override
	protected void setupBuffer(Node node) { 
		node.renderBuffer.align = align;
		super.setupBuffer(node);
	}
	 
	public Box setupBoxs(Node node,Box parent) {
		if(node==root) {
			return setupRoot(node,parent);
		}else {
			Box centerBox = new VBox(50,0);
			if(node.getParent()==root) {
				System.out.println(node.getIndex()+" i");
				if(node.getIndex()%2==0) {
					left.add(centerBox);
					
					align = Box.ALIGN_START;
					node.renderBuffer.align = align;
					//centerBox.align = Box.ALIGN_END;
				}else {
					align = Box.ALIGN_END; 
					node.renderBuffer.align = align;
					right.add(centerBox);
					//centerBox.align = Box.ALIGN_START;
				}
			}else
				parent.add(centerBox); 
			Box rbox = new VBox();
			Box border = new HBox(); 
			if(align != Box.ALIGN_START) {
				border.add(new Box(90,0));  
				border.add(rbox);
			}else {
				border.add(rbox);
				border.add(new Box(90,0));  
			} 
			centerBox.add(border);
			node.renderBuffer.onLayout(centerBox);
			rbox.space = itemSpace();
			centerBox.space = itemSpace();
			return rbox;
		}
	}

	private Box setupRoot(Node node, Box parent) {
		Box centerBox = new VBox(50,0);
		parent.align = Box.ALIGN_CENTER;
		centerBox.align = Box.ALIGN_CENTER;
		parent.add(centerBox);
		left.align = Box.ALIGN_END;
		right.align = Box.ALIGN_START;
		Box border = new HBox();
		border.align = Box.ALIGN_END;
		centerBox.add(border); 
		centerBox.add(node.renderBuffer.bound);
		border.add(left);
		border.add(right);
		return left;  
	}
/*
	@Override
	public PointF getFrontPoint(Node parent) { 
		if(parent.renderBuffer.align!=Box.ALIGN_START) {
			front.x = parent.getNodeBound().left; 
		}else {
			front.x = parent.getNodeBound().right;
		}
		front.y = parent.getNodeBound().centerY();
		
		return front;
	}

	@Override
	public PointF getBackPoint(Node parent) {
		if(parent.renderBuffer.align!=Box.ALIGN_START) {
			back.x = parent.getNodeBound().left+16; 
		}else {
			back.x = parent.getNodeBound().right-16;
		}
		back.y = parent.getNodeBound().top;
		return back;
	}
	*/
}
